<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <div slot="header">
        <b class="u-f-16">
          <span v-if="objForm.id">代理商收益记录</span>
        </b>
        <div class="u-right u-5mt">
          <el-button
            type="success"
            size="small"
            icon="el-icon-document-checked"
            v-if="objForm.check==1"
            @click="submitCheck()"
          >提交审核</el-button>
          <el-button size="small" icon="el-icon-back" @click="$router.go(-1)">返回</el-button>
        </div>
      </div>
      <el-form :model="objForm" :rules="rules" ref="objForm" label-width="100px" class="u-form">
        <el-form-item label="审核状态">
          <template>
            <el-radio-group v-model="subform.check" :disabled="objForm.check_time!=''">
              <el-radio :label="0">同意</el-radio>
              <el-radio :label="1">待审核</el-radio>
              <el-radio :label="2">拒绝</el-radio>
            </el-radio-group>
          </template>
        </el-form-item>
        <el-form-item label="拒绝原因" v-if="subform.check==2">
          <el-input type="textarea" v-model="subform.detail"></el-input>
        </el-form-item>
        <el-form-item label="审核时间" v-if="objForm.check_time!=''">
          <el-tag type="info">{{objForm.check_time}}</el-tag>
        </el-form-item>
        <el-form-item label="提现金额">
          <el-tag type="info">{{objForm.price}}</el-tag>
        </el-form-item>
        <el-form-item label="代理商">
          <el-tag type="info">{{objForm.agency_title}}</el-tag>
        </el-form-item>
        <el-form-item label="代理商账户">
          <el-tag type="info">{{objForm.agency_login_username}}</el-tag>
        </el-form-item>
        <el-form-item label="订单编号">
          <el-tag type="info">{{objForm.order_sn}}</el-tag>
        </el-form-item>
        <el-form-item label="付款编号">
          <el-tag type="info">{{objForm.pay_sn}}</el-tag>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import commonEdit from "@/mixins/common-edit";
export default {
  mixins: [commonEdit],
  data() {
    return {
      apiName: "agency",
      backRoute: "agencyExtractIndex", //成功跳转地址
      objForm: {
        id: "",
        agency_id: "", //代理商id
        agency_title: "", //代理商名称
        agency_img: "", //代理商图片
        agency_login_username: "", //代理商账号
        order_sn: "", //订单号
        pay_sn: "", //支付单号
        type: "", //收益类型
        detail: "", //说明
        last_price: "", //上次收益情况
        price: "", //金额
        check: 1, //0已审核 1待审核 2审核失败
        check_time: "" //审核时间
      },
      subform: {
        id: "",
        check: 1,
        detail: ""
      }
    };
  },
  methods: {
    submitCheck() {
      const self = this;
      self.$api[self.apiName]
        .agencyExtractStatus(self.subform)
        .then(response => {
          if (response.code == 1) {
            self.getInfo();
          }
        });
    },
    async getInfo() {
      const self = this;
      await self.beforeGetInfo();
      self.$api[self.apiName]
        .agencyExtractInfo(self.objForm.id)
        .then(response => {
          if (response.code == 1) {
            self.objForm = response.data;
            self.subform.check = self.objForm.check;
            self.subform.detail = self.objForm.remark;
            self.afterGetInfo();
          }
        });
    }
  },
  created() {
    if (this.$route.params.id) {
      this.objForm.id = this.$route.params.id;
      this.subform.id = this.$route.params.id;
    }
  }
};
</script>
